﻿

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using Common.Logging;

namespace BookStore.Platform.utils
{
    /// <summary>
	/// The Common Logging wrapper class which helps to resolve a instance for logging easily. 
    /// </summary>
    public static class Logger
    {		
        /// <summary>
		/// Get Common Logging instance by logger name.
        /// </summary>
		/// <param name="loggerName">logger name.</param>
		/// <returns>Returns logger instance.</returns>
        public static ILog Instance(string loggerName)
        {
			return LogManager.GetLogger(loggerName);
        }

		/// <summary>
		/// Get Common Logging instance by calling application type.
		/// </summary>
		/// <param name="type">caller type.</param>
		/// <returns>Returns logger instance.</returns>
		public static ILog Instance(Type type)
		{
			return LogManager.GetLogger(type);
		}

		/// <summary>
		/// Get Common Logging instance by calling instance.
		/// </summary>
		/// <param name="target">calling target instance.</param>
		/// <returns>Returns logger instance.</returns>
		public static ILog Instance(object target)
		{
			return Instance(target.GetType());
		}

		/// <summary>
		/// Logging info with formatting message by parameters.
		/// </summary>
		/// <param name="log"></param>
		/// <param name="messageFormat"></param>
		/// <param name="args"></param>
		public static void InfoFormat(this ILog log, string messageFormat, params object[] args)
		{
			log.Info(string.Format(CultureInfo.InvariantCulture, messageFormat, args));
		}

		/// <summary>
		/// Logging debug with formatting message by parameters.
		/// </summary>
		/// <param name="log"></param>
		/// <param name="messageFormat"></param>
		/// <param name="args"></param>
		public static void DebugFormat(this ILog log, string messageFormat, params object[] args)
		{
			log.Debug(string.Format(CultureInfo.InvariantCulture, messageFormat, args));
		}

		/// <summary>
		/// Logging warning with formatting message by parameters.
		/// </summary>
		/// <param name="log"></param>
		/// <param name="messageFormat"></param>
		/// <param name="args"></param>
		public static void WarnFormat(this ILog log, string messageFormat, params object[] args)
		{
			log.Warn(string.Format(CultureInfo.InvariantCulture, messageFormat, args));
		}

		/// <summary>
		/// Logging error with formatting message by parameters.
		/// </summary>
		/// <param name="log"></param>
		/// <param name="messageFormat"></param>
		/// <param name="args"></param>
		public static void ErrorFormat(this ILog log, string messageFormat, params object[] args)
		{
			log.Error(string.Format(CultureInfo.InvariantCulture, messageFormat, args));
		}

		/// <summary>
		/// Logging fatal with formatting message by parameters.
		/// </summary>
		/// <param name="log"></param>
		/// <param name="messageFormat"></param>
		/// <param name="args"></param>
		public static void FatalFormat(this ILog log, string messageFormat, params object[] args)
		{
			log.Fatal(string.Format(CultureInfo.InvariantCulture, messageFormat, args));
		}
    }
}
